//
// Created by buyongjiu on 2024/4/22.
//

#include "../include/Token.h"


Token::Token(TokenType type, int line, std::string value) {
    this->type = type;
    this->line = line;
    this->value = value;

}

Token::Token(const Token &token) {
    this->type = token.type;
    this->line = token.line;
    this->value = token.value;
}

std::string Token::toJSON() {
    std::string res = "{\"line\": ";
    res += std::to_string(this->line);
    res += ", \"type\": \"";
    switch(this->type) {
        case SEGMENT:
            res += "SEGMENT";
            break;
        case OPERATOR:
            res += "OPERATOR";
            break;
        case KEYWORD:
            res += "KEYWORD";
            break;
        case IDENTIFIER:
            res += "IDENTIFIER";
            break;
        case LITERALS:
            res += "LITERALS";
            break;
        case ERROR:
            res += "ERROR";
            break;
        case OTHERS:
            res += "OTHERS";
            break;
    }
    res += "\", \"value\": \"";
    res += this->value;
    res += "\"}";
    return res;
}

Token::~Token() {

}

std::string Token::toString() {
    std::string temp = "";
    switch (type) {
        case 0:
            temp += "SEGMENT";
            break;
        case 1:
            temp += "OPERATOR";
            break;
        case 2:
            temp += "KEYWORD";
            break;
        case 3:
            temp += "IDENTIFIER";
            break;
        case 4:
            temp += "LITERALS";
            break;
        case 5:
            temp += "ERROR";
            break;
        case 6:
            temp += "OTHERS";
            break;
}


    temp += " ";
    temp += std::to_string(this->line);
    temp += " ";
    temp += this->value;
    return temp;

}
